package com.jyj.springbootredis.ctrol;

import com.jyj.springbootredis.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @class: com.jyj.springbootredis.ctrol.indexAction
 * @description:
 * @author: jiangzengkui
 * @company: 教育家
 * @create: 2021-01-21 14:30
 */

@RestController
@RequestMapping("/redis")
public class indexAction {

    @Resource
    private RedisTemplate<String,Serializable> redisTemplate;

    @RequestMapping("/add")
    public  String index(){

       redisTemplate.opsForValue().set("strKey", "zwqh");
        System.out.println("ffffffff");

        UserEntity user=new UserEntity();
        user.setId(1L);
        user.setUserName("朝雾轻寒");
        user.setUserSex("男");
        redisTemplate.opsForValue().set("user", user);
        UserEntity user2 = (UserEntity) redisTemplate.opsForValue().get("user");
        System.out.println("user:"+user2.getId()+","+user2.getUserName()+","+user2.getUserSex());

        return "ok";
    }
}